package trainfengxing.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import trainfengxing.pojo.Hotel;
import trainfengxing.pojo.Result;
import trainfengxing.service.HotelService;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin
public class HotelController {
    @Autowired
    private HotelService hotelService;

    @GetMapping("/hotels")
    public Result getAllHotels() {
        log.info("查询所有酒店");
        List<Hotel> hotels = hotelService.getAllHotels();
        return Result.success(hotels);
    }

    @GetMapping("/hotels/{hotelID}")
    public Result getHotelById(@PathVariable Integer hotelID) {
        log.info("查询酒店详情，hotelID: {}", hotelID);
        Hotel hotel = hotelService.getHotelById(hotelID);
        return Result.success(hotel);
    }

    @PostMapping("/hotels")
    public Result addHotel(@RequestBody Hotel hotel) {
        log.info("添加新酒店: {}", hotel);
        hotelService.addHotel(hotel);
        return Result.success();
    }

    @PutMapping("/hotels")
    public Result updateHotel(@RequestBody Hotel hotel) {
        log.info("更新酒店信息: {}", hotel);
        hotelService.updateHotel(hotel);
        return Result.success();
    }

    @DeleteMapping("/hotels/{hotelID}")
    public Result deleteHotel(@PathVariable Integer hotelID) {
        log.info("删除酒店，hotelID: {}", hotelID);
        hotelService.deleteHotel(hotelID);
        return Result.success();
    }
}